import sys
sys.path
import sys
sys.path.append("test-modules")
import areaperi
print(areaperi.area(5,9))
print(areaperi.perimeter(5,9))
45 28
from areaperi import area
print(area(5,6))
30
import areaperi as areaPerimeter
print(areaPerimeter.area(5,6))
30
from areaperi import area as Ar, perimeter as Pr
print(Ar(3,5))
print(Pr(3,5))
15 16
from areaperi import *
print(areaperi.area(5,9))
print(areaperi.perimeter(5,9))
45 28
To create package ensure each package includes a file name __int__.py
import testpackage.ar
print(testpackage.ar.area(10,20))
200
from testpackage import pr
print(pr.perimeter(10,3))
26
| Method | Description |
|---|---|
math.acos() |
Returns the arc cosine of a number |
math.acosh() |
Returns the inverse hyperbolic cosine of a number |
math.asin() |
Returns the arc sine of a number |
math.asinh() |
Returns the inverse hyperbolic sine of a number |
math.atan() |
Returns the arc tangent of a number in radians |
math.atan2() |
Returns the arc tangent of y/x in radians |
math.atanh() |
Returns the inverse hyperbolic tangent of a number |
math.ceil() |
Rounds a number up to the nearest integer |
math.comb() |
Returns the number of ways to choose k items from n items without repetition and order |
math.copysign() |
Returns a float consisting of the value of the first parameter and the sign of the second parameter |
math.cos() |
Returns the cosine of a number |
math.cosh() |
Returns the hyperbolic cosine of a number |
math.degrees() |
Converts an angle from radians to degrees |
math.dist() |
Returns the Euclidean distance between two points (p and q), where p and q are the coordinates of that point |
math.erf() |
Returns the error function of a number |
math.erfc() |
Returns the complementary error function of a number |
math.exp() |
Returns E raised to the power of x |
math.expm1() |
Returns Ex - 1 |
math.fabs() |
Returns the absolute value of a number |
math.factorial() |
Returns the factorial of a number |
math.floor() |
Rounds a number down to the nearest integer |
math.fmod() |
Returns the remainder of x/y |
math.frexp() |
Returns the mantissa and the exponent, of a specified number |
math.fsum() |
Returns the sum of all items in any iterable (tuples, arrays, lists, etc.) |
math.gamma() |
Returns the gamma function at x |
math.gcd() |
Returns the greatest common divisor of two integers |
math.hypot() |
Returns the Euclidean norm |
math.isclose() |
Checks whether two values are close to each other, or not |
math.isfinite() |
Checks whether a number is finite or not |
math.isinf() |
Checks whether a number is infinite or not |
math.isnan() |
Checks whether a value is NaN (not a number) or not |
math.isqrt() |
Rounds a square root number downwards to the nearest integer |
math.ldexp() |
Returns the inverse of math.frexp() which is x * (2**i) of the given numbers x and i |
math.lgamma() |
Returns the log gamma value of x |
math.log() |
Returns the natural logarithm of a number, or the logarithm of number to base |
math.log10() |
Returns the base-10 logarithm of x |
math.log1p() |
Returns the natural logarithm of 1+x |
math.log2() |
Returns the base-2 logarithm of x |
math.perm() |
Returns the number of ways to choose k items from n items with order and without repetition |
math.pow() |
Returns the value of x to the power of y |
math.prod() |
Returns the product of all the elements in an iterable |
math.radians() |
Converts a degree value into radians |
math.remainder() |
Returns the closest value that can make numerator completely divisible by the denominator |
math.sin() |
Returns the sine of a number |
math.sinh() |
Returns the hyperbolic sine of a number |
math.sqrt() |
Returns the square root of a number |
math.tan() |
Returns the tangent of a number |
math.tanh() |
Returns the hyperbolic tangent of a number |
math.trunc() |
Returns the truncated integer parts of a number |
import math
# List all functions in the math module and their docstrings
math_functions = [item for item in dir(math) if callable(getattr(math, item))]
for function_name in math_functions:
function = getattr(math, function_name)
docstring = help(function)
if docstring is not None:
print(f"{function_name}:")
print(docstring)
print("\n")
Help on class BuiltinImporter in module importlib._bootstrap:
class BuiltinImporter(builtins.object)
| Meta path import for built-in modules.
|
| All methods are either class or static methods to avoid the need to
| instantiate the class.
|
| Class methods defined here:
|
| create_module(spec) from builtins.type
| Create a built-in module
|
| exec_module(module) from builtins.type
| Exec a built-in module
|
| find_module(fullname, path=None) from builtins.type
| Find the built-in module.
|
| If 'path' is ever specified then the search is considered a failure.
|
| This method is deprecated. Use find_spec() instead.
|
| find_spec(fullname, path=None, target=None) from builtins.type
|
| get_code(fullname) from builtins.type
| Return None as built-in modules do not have code objects.
|
| get_source(fullname) from builtins.type
| Return None as built-in modules do not have source code.
|
| is_package(fullname) from builtins.type
| Return False as built-in modules are never packages.
|
| load_module = _load_module_shim(fullname) from builtins.type
| Load the specified module into sys.modules and return it.
|
| This method is deprecated. Use loader.exec_module instead.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| module_repr(module)
| Return repr for the module.
|
| The method is deprecated. The import machinery does the job itself.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
Help on built-in function acos in module math:
acos(x, /)
Return the arc cosine (measured in radians) of x.
Help on built-in function acosh in module math:
acosh(x, /)
Return the inverse hyperbolic cosine of x.
Help on built-in function asin in module math:
asin(x, /)
Return the arc sine (measured in radians) of x.
Help on built-in function asinh in module math:
asinh(x, /)
Return the inverse hyperbolic sine of x.
Help on built-in function atan in module math:
atan(x, /)
Return the arc tangent (measured in radians) of x.
Help on built-in function atan2 in module math:
atan2(y, x, /)
Return the arc tangent (measured in radians) of y/x.
Unlike atan(y/x), the signs of both x and y are considered.
Help on built-in function atanh in module math:
atanh(x, /)
Return the inverse hyperbolic tangent of x.
Help on built-in function ceil in module math:
ceil(x, /)
Return the ceiling of x as an Integral.
This is the smallest integer >= x.
Help on built-in function copysign in module math:
copysign(x, y, /)
Return a float with the magnitude (absolute value) of x but the sign of y.
On platforms that support signed zeros, copysign(1.0, -0.0)
returns -1.0.
Help on built-in function cos in module math:
cos(x, /)
Return the cosine of x (measured in radians).
Help on built-in function cosh in module math:
cosh(x, /)
Return the hyperbolic cosine of x.
Help on built-in function degrees in module math:
degrees(x, /)
Convert angle x from radians to degrees.
Help on built-in function erf in module math:
erf(x, /)
Error function at x.
Help on built-in function erfc in module math:
erfc(x, /)
Complementary error function at x.
Help on built-in function exp in module math:
exp(x, /)
Return e raised to the power of x.
Help on built-in function expm1 in module math:
expm1(x, /)
Return exp(x)-1.
This function avoids the loss of precision involved in the direct evaluation of exp(x)-1 for small x.
Help on built-in function fabs in module math:
fabs(x, /)
Return the absolute value of the float x.
Help on built-in function factorial in module math:
factorial(x, /)
Find x!.
Raise a ValueError if x is negative or non-integral.
Help on built-in function floor in module math:
floor(x, /)
Return the floor of x as an Integral.
This is the largest integer <= x.
Help on built-in function fmod in module math:
fmod(x, y, /)
Return fmod(x, y), according to platform C.
x % y may differ.
Help on built-in function frexp in module math:
frexp(x, /)
Return the mantissa and exponent of x, as pair (m, e).
m is a float and e is an int, such that x = m * 2.**e.
If x is 0, m and e are both 0. Else 0.5 <= abs(m) < 1.0.
Help on built-in function fsum in module math:
fsum(seq, /)
Return an accurate floating point sum of values in the iterable seq.
Assumes IEEE-754 floating point arithmetic.
Help on built-in function gamma in module math:
gamma(x, /)
Gamma function at x.
Help on built-in function gcd in module math:
gcd(x, y, /)
greatest common divisor of x and y
Help on built-in function hypot in module math:
hypot(x, y, /)
Return the Euclidean distance, sqrt(x*x + y*y).
Help on built-in function isclose in module math:
isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)
Determine whether two floating point numbers are close in value.
rel_tol
maximum difference for being considered "close", relative to the
magnitude of the input values
abs_tol
maximum difference for being considered "close", regardless of the
magnitude of the input values
Return True if a is close in value to b, and False otherwise.
For the values to be considered close, the difference between them
must be smaller than at least one of the tolerances.
-inf, inf and NaN behave similarly to the IEEE 754 Standard. That
is, NaN is not close to anything, even itself. inf and -inf are
only close to themselves.
Help on built-in function isfinite in module math:
isfinite(x, /)
Return True if x is neither an infinity nor a NaN, and False otherwise.
Help on built-in function isinf in module math:
isinf(x, /)
Return True if x is a positive or negative infinity, and False otherwise.
Help on built-in function isnan in module math:
isnan(x, /)
Return True if x is a NaN (not a number), and False otherwise.
Help on built-in function ldexp in module math:
ldexp(x, i, /)
Return x * (2**i).
This is essentially the inverse of frexp().
Help on built-in function lgamma in module math:
lgamma(x, /)
Natural logarithm of absolute value of Gamma function at x.
Help on built-in function log in module math:
log(...)
log(x, [base=math.e])
Return the logarithm of x to the given base.
If the base not specified, returns the natural logarithm (base e) of x.
Help on built-in function log10 in module math:
log10(x, /)
Return the base 10 logarithm of x.
Help on built-in function log1p in module math:
log1p(x, /)
Return the natural logarithm of 1+x (base e).
The result is computed in a way which is accurate for x near zero.
Help on built-in function log2 in module math:
log2(x, /)
Return the base 2 logarithm of x.
Help on built-in function modf in module math:
modf(x, /)
Return the fractional and integer parts of x.
Both results carry the sign of x and are floats.
Help on built-in function pow in module math:
pow(x, y, /)
Return x**y (x to the power of y).
Help on built-in function radians in module math:
radians(x, /)
Convert angle x from degrees to radians.
Help on built-in function remainder in module math:
remainder(x, y, /)
Difference between x and the closest integer multiple of y.
Return x - n*y where n*y is the closest integer multiple of y.
In the case where x is exactly halfway between two multiples of
y, the nearest even value of n is used. The result is always exact.
Help on built-in function sin in module math:
sin(x, /)
Return the sine of x (measured in radians).
Help on built-in function sinh in module math:
sinh(x, /)
Return the hyperbolic sine of x.
Help on built-in function sqrt in module math:
sqrt(x, /)
Return the square root of x.
Help on built-in function tan in module math:
tan(x, /)
Return the tangent of x (measured in radians).
Help on built-in function tanh in module math:
tanh(x, /)
Return the hyperbolic tangent of x.
Help on built-in function trunc in module math:
trunc(x, /)
Truncates the Real x to the nearest Integral toward 0.
Uses the __trunc__ magic method.
import math
# Function for which you want to print the docstring
function_name = "sqrt" # Change this to the name of the function you want to examine
# Get the function object
function = getattr(math, function_name)
# Print the docstring
print(function.__doc__)
import math
x = 10
y = 23
print(math.factorial(x))
print(math.floor(x))
print(math.gcd(x,y))
print(math.isfinite(x))
print(math.isinf(x))
3628800 10 1 True False
a = [1,2,3,4,5,6,7,8,9,10]
print(math.fsum(a))
55.0
x = 10
print(math.log10(x))
print(math.log1p(x))
print(math.log2(x))
print(math.exp(x))
1.0 2.3978952727983707 3.321928094887362 22026.465794806718